#ifndef __INITIAL_EVENT_HPP__
#define __INITIAL_EVENT_HPP__

#include "base_event.hpp"

namespace run_code_event_space {

struct initial_event : base_event<initial_event>  {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context);
};

template <class U>
ProcessStatus initial_event::execute_impl(run_code_context_t<U>& context) {
    const RuncodeParams& params = context.params;
    if constexpr (contains_v<U, SpecialJudge, InteractiveJudge>) {
        if (context.judge_type.spjFile.empty()) {
            Log::instance().getError() << "spjFile not found\n";
            return ProcessStatus{ 
                        .result = LESS_SPJFILE,
                        .error = "spjFile not found",
                    };
        }
    } else if constexpr (std::is_same_v<U, TemplateJudge>) {
        if (context.judge_type.stdFile.empty()) {
            Log::instance().getError() << "stdFile not found\n";
            return ProcessStatus{ 
                        .result = LESS_SPJFILE,
                        .error = "TemplateJudge must be need stdFile",
                    };
        }
#ifdef ENABLE_DB_JUDGE
    } else if constexpr (contains_v<U, DatabaseSelectJudge, DatabaseModifyJudge>) {
        if (context.judge_type.createTableFile.empty()) {
            Log::instance().getError() << "create table file not found\n";
            return ProcessStatus{ 
                        .result = LESS_SPJFILE,
                        .error = "create table file not found",
                    };
        }
#endif
    }
    return ProcessStatus{ .result = RUN_OK };
}

};

#endif /* __INITIAL_EVENT_HPP__ */
